package com.woniu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.mapper.UserVoMapper;
import com.woniu.service.UserVoService;
import com.woniu.vo.ConditionVo;
import com.woniu.vo.UserVo;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;

@Service
public class UserVoServiceImpl extends ServiceImpl<UserVoMapper, UserVo> implements UserVoService {

    @Resource
    private UserVoMapper userVoMapper;

    @Override
    public IPage<UserVo> getUser(ConditionVo conditionVo) {

        Page<UserVo> page = new Page<>(conditionVo.getCurrent(),conditionVo.getSize());
        QueryWrapper<UserVo> ew = new QueryWrapper<UserVo>();
        if(!ObjectUtils.isEmpty(conditionVo.getTel())){
           ew.like("u.tel",conditionVo.getTel());
        }
        if(!ObjectUtils.isEmpty(conditionVo.getUsername())){
            ew.like("u.username",conditionVo.getUsername());
        }
        if(!ObjectUtils.isEmpty(conditionVo.getRid())){
            ew.eq("role_id",conditionVo.getRid());
        }
        ew.eq("u.deleted",0);
        return userVoMapper.getUser(page,ew);
    }
}
